/**
 * 结束单人
 */
class FinishPlayerItem extends eui.Component {

    private img_bg: eui.Image;

    private head: HeadIcon;
    private lab_nick: eui.Label;
    private lab_id: eui.Label;
    private zan: eui.Image;

    private textGroup: eui.Group;
    private zhuang: eui.Group;
    private lab_zhuang: eui.Label;
    private hupai: eui.Group;
    private lab_hupai: eui.Label;
    private zimo: eui.Group;
    private lab_zimo: eui.Label;
    private dianpao: eui.Group;
    private lab_dianpao: eui.Label;
    private jiepao: eui.Group;
    private lab_jiepao: eui.Label;
    private angang: eui.Group;
    private lab_angang: eui.Label;
    private minggang: eui.Group;
    private lab_minggang: eui.Label;

    private lab_zongfen: eui.Label;

    private win: eui.Image;
    private pao: eui.Image;

    private card_group: eui.Group;
    private img_reward_type: eui.Image;
    private lab_reward_num: eui.BitmapLabel;

    public player: any;

    constructor(player: any) {
        super();

        this.skinName = "FinishPlayerItemSkin";

        this.player = player;
    }

    childrenCreated() {
        super.childrenCreated();

        this.head.skinState = "intheend";

        this.textGroup.removeChild(this.jiepao);
        this.textGroup.removeChild(this.angang);
        this.textGroup.removeChild(this.minggang);

        gameManager.i.addEventListener(GameEventType.UPDATE_ASSESS_DATA, this.onUpdate, this);
    }

    private onUpdate(data: any) {
        let appraise: any = data;
        if (appraise && appraise.hasOwnProperty(this.player.uid)) {
            this.zan.source = appraise[this.player.uid] == 1 ? "assess_ico_good_1" : "assess_ico_bad_1";
        }
    }

    refresh() {

        let data = game.roomPlayers[this.player.uid];
        this.player.cai = data.cai;
        this.player.zan = data.zan;

        this.head.update(this.player);
        this.lab_nick.text = this.player.nick;
        this.lab_id.text = 'ID:' + this.player.uid;

        this.zan.source = "assess_ico_good_1";
        this.zan.visible = this.player.uid != game.player.uid;

        this.lab_zhuang.text = "" + this.player.zhuang_num;
        this.lab_hupai.text = "" + this.player.hu_num;
        this.lab_zimo.text = "" + this.player.zimo_num;
        this.lab_dianpao.text = "" + this.player.pao_num;
        this.lab_jiepao.text = "" + this.player.paorcv_num;
        this.lab_angang.text = "" + this.player.gang_an_num;
        this.lab_minggang.text = "" + this.player.gang_ming_num;

        this.lab_zongfen.text = "" + this.player.cur;
        this.lab_zongfen.textColor = this.player.cur >= 0 ? 0xdbe036 : 0x60d6dd;

        this.win.visible = this.player["iswin"];
        this.pao.visible = this.player["ispao"];

        this.img_bg.source = this.player["iswin"] ? 'finish_itembg_winner' : 'finish_itembg_loser';

        let new_card: number = +this.player.new_card;
        if (new_card > 0) {
            this.img_reward_type.source = +this.player.pos == 1 ? "finish_text_owner" : "finish_text_new";
            this.lab_reward_num.text = `x${new_card}`;
        }

        this.card_group.visible = new_card > 0;
    }
}